package config;


import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

public class ServerConfig {

	private String propsPath="/server/connection.properties";
	private final static Properties prop = new Properties();
	private InputStream in;
	
	private static String ipServer="";
	private static String portServer="";
	private static String postfixServer="";
	private static String socketServer="";

	
	private static ServerConfig conf;
	
	private ServerConfig() throws IOException
	{
		in = this.getClass().getResourceAsStream(propsPath);
		prop.load(in);
				
	}
	
	public static ServerConfig getInstance()
	{
		if(conf==null)
		{
			try {
				conf = new ServerConfig();
				listProps();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return conf;		
	}
	
	private static void listProps()
	{

	    Enumeration<?> e = prop.propertyNames();

	    System.out.println("USTAWIENIA:  ");
	    while (e.hasMoreElements()) {
	      String key = (String) e.nextElement();
	      System.out.println("KEY:  " + key.trim() + "  =  " + prop.getProperty(key));

	      if (key.equals("ip")) 
	      {
	    	  ipServer=prop.getProperty(key).trim();
	      }
	      else if (key.equals("port")) 
	      {
	    	  portServer=prop.getProperty(key).trim();
	      }
	      else if (key.equals("postfix")) 
	      {
	    	  postfixServer=prop.getProperty(key).trim();
	      }
	      else if (key.equals("socket")) 
	      {
	    	  socketServer=prop.getProperty(key).trim();
	      }
	     
	      
 
	    }
	}

	public static String getIpServer() {
		return ServerConfig.getInstance().ipServer.trim();
	}

	public static void setIpServer(String ipServer) {
		ServerConfig.ipServer = ipServer.trim();
	}

	public static String getPortServer() {
		return ServerConfig.getInstance().portServer.trim();
	}

	public static void setPortServer(String portServer) {
		ServerConfig.portServer = portServer.trim();
	}

	public static String getPostfixServer() {
		return ServerConfig.getInstance().postfixServer.trim();
	}

	public static void setPostfixServer(String postfixServer) {
		ServerConfig.postfixServer = postfixServer.trim();
	}

	public static String getSocketServer() {
		return ServerConfig.getInstance().socketServer.trim();
	}

	public static void setSocketServer(String socketServer) {
		ServerConfig.socketServer = socketServer.trim();
	}
	



	
}
